const path = require("path");
const express = require("express");
const cors = require("cors");
const morgan = require("morgan");
const { init: initDB, Counter, Order } = require("./db");
const history = require('connect-history-api-fallback');
const router = require('./src/router/router');

const app = express();
const logger = morgan("tiny");
app.use(express.urlencoded({ extended: false }));
app.use(express.json());
app.use(cors());
app.use(logger);

app.use(express.static(path.join(__dirname, 'view')));
app.use(history());


// 路由
app.use('/api', router)

const port = process.env.PORT || 3003;

async function bootstrap() {
  await initDB();
  app.listen(port, () => {
    console.log("启动成功", port);
  });
}

bootstrap();
